/** TS类型系统中没有加减乘除运算符，但是可以通过构造不同的数组然后取length的方式来完成数值计算，把数值的加减乘除转化为对数组的提取和构造 */

// --------------------------------------------------- 加减乘除 -----------------------------------------------------------------------------------------
// 先利用递归实现一个length长度的数组
type BuildArray<Length extends number, Ele = unknown, Arr extends unknown[] = []> = Arr["length"] extends Length ? Arr : BuildArray<Length, Ele, [...Arr, Ele]>;


// 加法
type GetAdd<N1 extends number, N2 extends number> = [...BuildArray<N1>, ...BuildArray<N2>]["length"]
type GetAddR = GetAdd<1, 2>;

// 减法.思路是可以通过数组类型的提取来做。比如3长度的数组，取两个元素后，剩下的数组长度
type GetSubtract<N1 extends number, N2 extends number> = BuildArray<N1> extends [...BuildArray<N2>, ...infer Rest] ? Rest["length"] : never;
type GetSubtractR = GetSubtract<3, 1>;

// 乘法,就是多个加法结果的累加。递归的累加
type GetMultiply<N1 extends number, N2 extends number, Arr extends unknown[] = []> = N1 extends 0 ? Arr["length"] : GetMultiply<GetSubtract<N1, 1>, N2, [...Arr, ...BuildArray<N2>]>
type GetMultiplyR = GetMultiply<3, 4>

// 除法，递归的累减
type GetDivide<N1 extends number, N2 extends number, Arr extends unknown[] = []> = N1 extends 0 ? Arr["length"] : GetDivide<GetSubtract<N1, N2>, N2, [unknown, ...Arr]>
type GetDivideR = GetDivide<40, 4>;

// -------------------------------------------------------- 数组长度实现计数 ------------------------------------------------------------------------------------
// 字符串长度
type GetStrLen<Str extends string, Arr extends unknown[] = []> = Str extends `${string}${infer Rest}` ? GetStrLen<Rest, [...Arr, unknown]> : Arr["length"];
type GetStrLenR = GetStrLen<"123232">

// 两个数大小比较,利用Arr的不断加一个，看那个数最先等于长度，就是小的那个数值
type GetGreaterThan<N1 extends number, N2 extends number, Arr extends unknown[] = []> = N1 extends N2 ? false : Arr["length"] extends N2 ? true : Arr["length"] extends N1 ? false : GetGreaterThan<N1, N2, [...Arr, unknown];
type GetGreaterThanR1 = GetGreaterThan<3, 4>
type GetGreaterThanR2 = GetGreaterThan<4, 4>
type GetGreaterThanR3 = GetGreaterThan<4, 3>




























